package SecondeStage.XianCheng;

public class Thread02 {
    public static void main(String[] args) throws InterruptedException {
        Dog dog = new Dog();
        // dog.start(); 这里不能调用start方法
        //创建了Thread对象，把 dog对象(实现Runnable),放入了Thread
        Thread thread =new Thread(dog);
        thread.start();
        // 在主线程里通知线程退出
        Thread.sleep(10000);
        dog.setLoop(false);
    }
}

// 实现Runnable接口，开发线程
class Dog implements Runnable{
    private Boolean loop=true;
    @Override
    public void run() {
        while (loop){
            System.out.println("小狗汪汪叫"+ Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public Boolean getLoop() {
        return loop;
    }

    public void setLoop(Boolean loop) {
        this.loop = loop;
    }
}